
package system.base;

import framework.core.*;
import system.data.*;
/*
	Author    :chengbiao.he
	CreateTime:2008-02-25 09:29:27
*/
public class CheckSubSrv extends IHandler
{

	public CheckSubSrv() 
	{
		super();
	}
	private void deleteCheckSub(DBConnection con,SrvContext context) throws Exception
	{
		String[] ids = context.getParameterValues("ids");
		CheckSub obj = null;
		for(int i=0;i<ids.length;i++)
		{
			obj = CheckSub.fetch(con,ids[i]);
			if(obj!=null) obj.delete(con);
		}
	}
	private void saveCheckSub(DBConnection con,SrvContext context,ILoginContext loginContext) throws Exception
	{
		String id = context.getString("Id",null);
		CheckSub obj;
		if((id==null)||(id.equals("")))   //add
		{
			obj = CheckSub.fetch();
    	}
    	else                     //update
    	{
    		obj = CheckSub.fetch(con,id);
    	}
		CheckSubPageData data = (CheckSubPageData)PageData.fromForm(context,CheckSubPageData.class);
		context.setValue("CheckSubPageData",data);
		obj.fill(data);
		obj.save(con);
	}
	private void listCheckSub(DBConnection con,SrvContext context,String path) throws Exception
	{
		CheckSubSearchEvent event = (CheckSubSearchEvent)SearchEvent.fromForm(context,CheckSubSearchEvent.class);
		context.setSessionValue("CheckSubSearchEvent",event);
		context.setNextUrl(path+"CheckSubList.jsp");
	}
	private void backCheckSub(DBConnection con,SrvContext context,String path) throws Exception
	{
		context.setNextUrl(path+"CheckSubList.jsp");
	}
	
	public void doAction(DBConnection con,SrvContext context,ILoginContext loginContext) throws Exception
	{
		String action_code = context.getActionCode();
		String path = "/system/base/";
		
		if(action_code.equalsIgnoreCase("listCheckSub"))
		{
			listCheckSub(con,context,path);
			return;
		}
		if(action_code.equalsIgnoreCase("viewCheckSub"))
		{
			String id = context.getString("Id",null);
			CheckSub obj = CheckSub.fetch(con,id);
			context.setValue("CheckSub",obj);
			context.setNextUrl(path+"CheckSubView.jsp");
			return;
		}
		if(action_code.equalsIgnoreCase("deleteCheckSub"))
		{
			context.setErrorUrl(path+"CheckSubList.jsp");
			deleteCheckSub(con,context);
			backCheckSub(con,context,path);
			return;
		}
			
		if(action_code.equalsIgnoreCase("toAddCheckSub"))
		{
			CheckSub obj = CheckSub.fetch();
			CheckSubPageData data = (CheckSubPageData)PageData.fromTable(obj,CheckSubPageData.class);
			context.setValue("CheckSubPageData",data);
			context.setNextUrl(path+"CheckSubEdit.jsp");
			return;
		}
		if(action_code.equalsIgnoreCase("toUpdateCheckSub"))
		{
			String id = context.getString("Id",null);
			CheckSub obj = CheckSub.fetch(con,id);
			CheckSubPageData data = (CheckSubPageData)PageData.fromTable(obj,CheckSubPageData.class);
			context.setValue("CheckSubPageData",data);
			context.setNextUrl(path+"CheckSubEdit.jsp");
			return;
		}
		if(action_code.equalsIgnoreCase("toCopyCheckSub"))
		{
			String id = context.getString("Id",null);
			CheckSub obj = CheckSub.copy(CheckSub.fetch(con,id));
			CheckSubPageData data = (CheckSubPageData)PageData.fromTable(obj,CheckSubPageData.class);
			context.setValue("CheckSubPageData",data);
			context.setNextUrl(path+"CheckSubEdit.jsp");
			return;
		}
		if(action_code.equalsIgnoreCase("saveCheckSub"))
		{
			context.setErrorUrl(path+"CheckSubEdit.jsp");
			saveCheckSub(con,context,loginContext);
			backCheckSub(con,context,path);
			return;
		}
		if(action_code.equalsIgnoreCase("saveAndNewCheckSub"))
		{
			context.setErrorUrl(path+"CheckSubEdit.jsp");
			saveCheckSub(con,context,loginContext);
			CheckSub obj = CheckSub.fetch();
			CheckSubPageData data = (CheckSubPageData)PageData.fromTable(obj,CheckSubPageData.class);
			context.setValue("CheckSubPageData",data);
			context.setNextUrl(path+"CheckSubEdit.jsp");			
			return;
		}
		if(action_code.equalsIgnoreCase("backListCheckSub"))
		{
			backCheckSub(con,context,path);
			return;
		}
		
		//add by chengbiao.he start

		//add by chengbiao.he end

		Logger.throwException("CheckSubSrv","unknown action_code="+action_code);
	}
}
